package com.settlement.system.model.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.settlement.system.common.base.BaseEntity;
import com.settlement.system.common.util.StringUtils;
import com.settlement.system.model.vo.TbOrderImportVo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 淘宝订单表
 * </p>
 *
 * @author huangrensen
 * @since 2023-08-05
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TbOrder extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;


    private String orderNo;


    private String payNo;


    private String payDetail;


    private BigDecimal buyerDuePayAmount = BigDecimal.ZERO;


    private BigDecimal buyerDuePayPostage = BigDecimal.ZERO;


    private BigDecimal buyerPayCredits = BigDecimal.ZERO;


    private BigDecimal totalAmount = BigDecimal.ZERO;


    private BigDecimal returnCredits = BigDecimal.ZERO;


    private BigDecimal buyerActualPayAmount = BigDecimal.ZERO;


    private BigDecimal buyerActualPayCredits = BigDecimal.ZERO;


    private String orderStatus;


    private String buyerMessage;


    private String receiverName;


    private String recieverAddress;


    private String deliveryMethod;


    private String mobile;


    private String phone;


    private String virtualNoExpireTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime orderCreateTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime orderPayTime;


    private String goodsTitle;


    private String goodsType;


    private String logisticsNo;


    private String logisticsCompany;


    private String remark;


    private Integer goodsNum;


    private String orderCloseReason;


    private BigDecimal sellerServiceFee = BigDecimal.ZERO;


    private BigDecimal buyerServiceFee = BigDecimal.ZERO;


    private String invoiceTitle;


    private String mobileOrder;


    private String stepOrderInfo;


    private String privilegeOrderId;


    private String hasUploadContract;


    private String hasUploadReceipt;


    private String hasPayBehalf;


    private String depositRank;


    private String newSku;


    private String newRecieveAddress;


    private String exceptionMessage;


    private String tmallDeduct;


    private String jfbDeduct;


    private String o2oTrade;


    private String newTradeType;


    private String newTradeName;


    private String newTradeId;


    private String newTradeDeliveryName;


    private String newTradeDeliveryId;


    private BigDecimal returnAmount = BigDecimal.ZERO;


    private String bookingStore;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime receiveTime;


    private BigDecimal paySellerAmount = BigDecimal.ZERO;


    private String invoiceTip;


    private String hasCreditBuy;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime experienceEndTime;


    private String aheadPresent;


    private String deliveryType;


    private String liveReturnStatus;


    private BigDecimal cashbackAmount = BigDecimal.ZERO;


    private BigDecimal delayPayAmount = BigDecimal.ZERO;


    private String newDealStoreName;


    private String newDealStoreId;


    private String newDealAgentId;


    private String presaleOrder;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime deliveryTime;


    private String mainOrderNum;


    private String differentOrder;

    @TableField(exist = false)
    private String tableName;

    // 所属平台
    private String platform;

    // 登陆账号
    private String userName;

    // 店铺ID
    private Long storeId;

    // 店铺名称
    private String storeName;

    // 关联核销单号
    private String auditNo;

    // 账单月份
    private String billMonth;

    public static List<String> getDateColumn() {
        List<String> columnList = new ArrayList<>();
        columnList.add("orderCreateTime");
        columnList.add("orderPayTime");
        columnList.add("receiveTime");
        columnList.add("experienceEndTime");
        columnList.add("deliveryTime");
        return columnList;
    }

    public static List<String> getBigDecimalColumn() {
        List<String> columnList = new ArrayList<>();
        columnList.add("buyerDuePayAmount");
        columnList.add("buyerDuePayPostage");
        columnList.add("buyerPayCredits");
        columnList.add("totalAmount");
        columnList.add("returnCredits");
        columnList.add("buyerActualPayAmount");
        columnList.add("buyerActualPayCredits");
        columnList.add("sellerServiceFee");
        columnList.add("buyerServiceFee");
        columnList.add("returnAmount");
        columnList.add("paySellerAmount");
        columnList.add("cashbackAmount");
        columnList.add("delayPayAmount");
        return columnList;
    }

    public void transfer(TbOrderImportVo vo) {
        try {
            this.orderNo = vo.getOrderNo();
            this.payNo = vo.getPayNo();
            this.payDetail = vo.getPayDetail();
            if (StringUtils.hasText(vo.getBuyerDuePayAmount())) {
                this.buyerDuePayAmount = new BigDecimal(StringUtils.replaceStr(vo.getBuyerDuePayAmount(), "元", "").replaceAll(
                        "null", "").trim());
            }
            if (StringUtils.hasText(vo.getBuyerDuePayPostage())) {
                this.buyerDuePayPostage = new BigDecimal(StringUtils.replaceStr(vo.getBuyerDuePayPostage(), "元", "").replaceAll(
                        "null", "").trim());
            }
            if (StringUtils.hasText(vo.getBuyerPayCredits())) {
                this.buyerPayCredits = new BigDecimal(StringUtils.replaceStr(vo.getBuyerPayCredits(), "元", "").replaceAll("null",
                        "").trim());
            }
            if (StringUtils.hasText(vo.getTotalAmount())) {
                this.totalAmount = new BigDecimal(vo.getTotalAmount().replaceAll("元", "").replaceAll("null", "").trim());
            }
            if (StringUtils.hasText(vo.getReturnCredits())) {
                this.returnCredits = new BigDecimal(vo.getReturnCredits().replaceAll("元", "").replaceAll("null", "").trim());
            }
            if (StringUtils.hasText(vo.getBuyerActualPayAmount())) {
                this.buyerActualPayAmount = new BigDecimal(vo.getBuyerActualPayAmount().replaceAll("元", "").replaceAll("null", "").trim());
            }
            if (StringUtils.hasText(vo.getBuyerActualPayCredits())) {
                this.buyerActualPayCredits = new BigDecimal(vo.getBuyerActualPayCredits().replaceAll("元", "").replaceAll("null", "").trim());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
